import { defineStore } from "pinia";
import { reqC1List, reqC2List, reqC3List } from '@/api/product/attr/attr'
import type {categoryStoreStateType} from './interface/category'
const categoryStore = defineStore('category', {
    state: ():categoryStoreStateType => {
        return {
            c1List: [],
            c2List: [],
            c3List: [],
            c1Id: '',
            c2Id: '',
            c3Id: '',
        }
    },
    actions: {
        async getC1List() {
            let result = await reqC1List()
            //   console.log(result);
            this.c1List = result
        },
        async getC2List() {
            // 触发一级事件清除二级三级id和数据
            this.c2List=[]
            this.c3List=[]
            this.c2Id=''
            this.c3Id=''
            let result = await reqC2List(this.c1Id)
            this.c2List = result
        },
        async getC3List() {
             // 触发二级事件清除三级id和数据
             this.c3List=[]
             this.c3Id=''
            let result = await reqC3List(this.c2Id)
            this.c3List = result
        }
    }
})
export default categoryStore